﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TS.Bussiness;
using TS.Commons;
using TS.Entities;

namespace Tranco.Shares
{
    public partial class Site1 : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int userId = Session["TracoUserId"].ToNumeric();
            string pageName = Path.GetFileNameWithoutExtension(Page.AppRelativeVirtualPath) + ".aspx";

            ConfigurationBussiness cbu = new ConfigurationBussiness();

            if (Session["TracoGroupId"].ToNumeric() != 1)
            {
                var config = cbu.GetConfig();
                if (config.IsClosed == 1)
                    Response.Redirect("~/Maintenance.aspx");
            }
            UserBussiness bu = new UserBussiness();
            User user = bu.GetRole(userId, pageName);
            if (user == null) Response.Redirect("~/ErrorPermission.aspx");
            if (user.Userid < 0 || user.Userid != userId || user.IsLock == 1)
            {
                Response.Redirect("~/ErrorPermission.aspx");
            }

            if (!IsPostBack)
            {
                cbu.UpdateViewCount();
            }
        }
    }
}